A pager using a linear allocation algorithm. More...
Public Member Functions | |
LinearPager (size_t pageSize) | |
~LinearPager ()=default | |
size_t | getPageSize () const |
size_t | getCurrentOffset () const |
size_t | getAllocatedPageCount () const |
size_t | getAvailablePageCount () const |
T | allocate (size_t size, size_t alignment=1) |
void | reset () |
size_t | getCurrentPageFreeMemory () const |
A pager using a linear allocation algorithm.
A linear pager will allocate sequentially in the active page. When the page is full, a new page is allocated. Resetting the pager resets all allocations. This kind of pager can be useful in scenarios where allocations are used for a purpose and can be fred right after.
For instance, in a 3d renderer, it can be used to page resources used on a per frame basis (allocate for the frame, reset, reuse allocations for next frame).
nkMemory::LinearPager< T, U >::LinearPager | ( | size_t | pageSize | ) |
Constructor.
pageSize | The size wanted for pages within the pager. |
|
default |
Destructor.
size_t nkMemory::LinearPager< T, U >::getPageSize | ( | ) | const |
size_t nkMemory::LinearPager< T, U >::getCurrentOffset | ( | ) | const |
size_t nkMemory::LinearPager< T, U >::getAllocatedPageCount | ( | ) | const |
size_t nkMemory::LinearPager< T, U >::getAvailablePageCount | ( | ) | const |
T nkMemory::LinearPager< T, U >::allocate | ( | size_t | size, |
size_t | alignment = 1 |
||
) |
Requests an allocation.
size | The size needed for the allocation. |
alignment | The alignment needed for the allocation. |
void nkMemory::LinearPager< T, U >::reset | ( | ) |
Resets the status of the pager. This will make the pager reset its current tracking within the pages. Note that no memory will be freed. The point is to make already allocated memory usable again.
size_t nkMemory::LinearPager< T, U >::getCurrentPageFreeMemory | ( | ) | const |